package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.vo.CouponIndexVo;
import com.cskaoyan.bean.wx.vo.*;
import com.cskaoyan.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @date 2020/12/9 15:42
 */
@Service
public class HomeServiceImpl implements HomeService{
    @Autowired
    AdMapper adMapper;
    @Autowired
    BrandMapper brandMapper;
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    CouponMapper couponMapper;
    @Autowired
    TopicMapper topicMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GrouponRulesMapper grouponRulesMapper;

    @Override
    public NewGoodsList queryHomeList() {

        NewGoodsList newGoodsList = new NewGoodsList();
        //bannder
        AdExample adExample = new AdExample();
        AdExample.Criteria criteria = adExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        List<Ad> ads = adMapper.selectByExample(adExample);
        newGoodsList.setBanner(ads);
        //brandList
        PageHelper.startPage(1,4);
        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria brandCriteria = brandExample.createCriteria();
        brandCriteria.andDeletedEqualTo(false);
        List<Brand> brandList = brandMapper.selectByExample(brandExample);
        newGoodsList.setBrandList(brandList);
        //channel

        List<IndexCategorityVo> categories = categoryMapper.selectChannel();
        newGoodsList.setChannel(categories);

        //couponList
        List<CouponIndexVo> couponList=couponMapper.selectCouponIndex(0);
        newGoodsList.setCouponList(couponList);
        //floorGoodsList
        PageHelper.startPage(1,2);
        List<IndexFloorGoodsVo> floorGoodsList = categoryMapper.selectFloorGoods();
        newGoodsList.setFloorGoodsList(floorGoodsList);

        //grouponList
        List<IndexGrouponVo> grouponList = grouponRulesMapper.selectGroupon();
        newGoodsList.setGrouponList(grouponList);

        //newGoodsList
        PageHelper.startPage(1,6);
        String isnew = "is_new";
        List<IndexGoodsList> newGoods = goodsMapper.selectGoodsList(isnew);
        newGoodsList.setNewGoodsList(newGoods);
        //hotGoodsList
        PageHelper.startPage(1,6);
        String ishot = "is_hot";
        List<IndexGoodsList> hotGoods =goodsMapper.selectGoodsList(ishot);
        newGoodsList.setHotGoodsList(hotGoods);
        //topicList
        PageHelper.startPage(1,4);
        List<IndexTopicVo> topicVoList = topicMapper.selectTopic();
        newGoodsList.setTopicList(topicVoList);

        return newGoodsList;
    }
}
